<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Math::Random::Secure - Cryptographically-secure, cross-platform replacement for rand() - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Math-Random-Secure - MetaCPAN" href="https://metacpan.org/dist/Math-Random-Secure/releases.rss" />
        <link rel="canonical" href="./Math::Random::Secure.html" />
        <meta name="description" content="Cryptographically-secure, cross-platform replacement for rand()" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Math::Random::Secure" />
<meta name="twitter:title"       content="Math::Random::Secure" />
<meta name="twitter:description" content="Cryptographically-secure, cross-platform replacement for rand()" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Math::Random::Secure.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Math-Random-Secure was released.">
      <span class="relatize">12 Mar 2017 22:46:35 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Math-Random-Secure">Math-Random-Secure</a>
  </li>
  <li>
    Module version: 0.080001
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Math-Random-Secure/source/lib/Math/Random/Secure.pm">Source</a>
    (<a href="https://metacpan.org/dist/Math-Random-Secure/source/lib/Math/Random/Secure.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Math-Random-Secure/source/lib/Math/Random">Browse</a>
    (<a href="https://metacpan.org/dist/Math-Random-Secure/source/lib/Math/Random?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Math-Random-Secure/changes">Changes</a>
    </li>
    <li>
      <a rel="noopener nofollow" class="nopopup" href="https://github.com/frioux/Math-Random-Secure">Homepage</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Math-Random-Secure/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/frioux/Math-Random-Secure">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://github.com/frioux/Math-Random-Secure/issues">Issues</a>
      (0)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Math-Random-Secure+0.080001" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Random-Secure.html?oncpan=1&amp;distmat=1&amp;version=0.080001&amp;grade=2" style="color: #090">4804</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Random-Secure.html?oncpan=1&amp;distmat=1&amp;version=0.080001&amp;grade=3" style="color: #900">2</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Random-Secure.html?oncpan=1&amp;distmat=1&amp;version=0.080001&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/FREW/Math-Random-Secure-0.080001">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Math-Random-Secure who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 0
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Math-Random-Secure-0.080001/index.html">93.94% Coverage </a>
    </li>
    <li>
      License: artistic_2
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Math-Random-Secure/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/F/FR/FREW/Math-Random-Secure-0.080001.tar.gz">
      Download (<span itemprop="fileSize">17.01KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FFREW%2FMath-Random-Secure-0.080001%2Flib%2FMath%2FRandom%2FSecure.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Math-Random-Secure/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Math-Random-Secure/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Math-Random-Secure">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Math-Random-Secure">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Math/Random/Secure.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="FREW/Math-Random-Secure-0.080001"
>0.080001
  (FREW on 2017-03-12)</option>
<option
  
  value="FREW/Math-Random-Secure-0.08"
>0.08
  (FREW on 2016-10-16)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.06"
>0.06
  (MKANAT on 2011-01-25)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.05"
>0.05
  (MKANAT on 2011-01-07)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.04"
>0.04
  (MKANAT on 2011-01-05)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.03"
>0.03
  (MKANAT on 2010-12-30)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.02"
>0.02
  (MKANAT on 2010-12-29)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.01"
>0.01
  (MKANAT on 2010-12-28)</option>
<optgroup label="BackPAN">'
<option
  
  value="FREW/Math-Random-Secure-0.07"
>0.07
  (FREW on 2016-10-16)</option>
<option
  
  value="FREW/Math-Random-Secure-0.06"
>0.06
  (FREW on 2016-10-16)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/FREW/Math-Random-Secure-0.080001/diff/' + encodeURIComponent(this.value) + '/lib/Math/Random/Secure.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="FREW/Math-Random-Secure-0.080001"
>0.080001
  (FREW on 2017-03-12)</option>
<option
  
  value="FREW/Math-Random-Secure-0.08"
>0.08
  (FREW on 2016-10-16)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.06"
>0.06
  (MKANAT on 2011-01-25)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.05"
>0.05
  (MKANAT on 2011-01-07)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.04"
>0.04
  (MKANAT on 2011-01-05)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.03"
>0.03
  (MKANAT on 2010-12-30)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.02"
>0.02
  (MKANAT on 2010-12-29)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.01"
>0.01
  (MKANAT on 2010-12-28)</option>
<optgroup label="BackPAN">'
<option
  
  value="FREW/Math-Random-Secure-0.07"
>0.07
  (FREW on 2016-10-16)</option>
<option
  
  value="FREW/Math-Random-Secure-0.06"
>0.06
  (FREW on 2016-10-16)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Crypt::Random::Source" title="Crypt::Random::Source" class="ellipsis">Crypt::Random::Source</a></li>
  <li><a href="https://metacpan.org/pod/Math::Random::ISAAC" title="Math::Random::ISAAC" class="ellipsis">Math::Random::ISAAC</a></li>
  <li><a href="Moo.html" title="Moo" class="ellipsis">Moo</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Math::Random::Secure/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Math%3A%3ARandom%3A%3ASecure">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Math-Random-Secure">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/FREW/Math-Random-Secure-0.080001/view/lib/Math/Random/Secure.pm">This version</a>
    </li>
    <li>
      <a href="./Math::Random::Secure.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/DANAJ"><img src="https://www.gravatar.com/avatar/4a4266026e031466b19413bd15f805e7?d=identicon&amp;s=20" title="DANAJ" alt="DANAJ"></a>
<a class="display-all" href="https://metacpan.org/author/LUKAST"><img src="https://www.gravatar.com/avatar/befd90fe1bec8d75ae9c4938a0f28861?d=identicon&amp;s=20" title="LUKAST" alt="LUKAST"></a>
<a class="display-all" href="https://metacpan.org/author/SALVA"><img src="https://www.gravatar.com/avatar/026f1493e8fcd16015467901fa76e9ec?d=identicon&amp;s=20" title="SALVA" alt="SALVA"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Math-Random-Secure/plussers">3 PAUSE users</a>
</div>
<div>
    2 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 2 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-cpan-author="MKANAT"
      data-contrib-email="mkanat@cpan.org"
    >
      <a href="https://metacpan.org/author/MKANAT" class="cpan-author">
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d75c99cad584b9ce06ed814e1e54013d?d=identicon&amp;s=20" />
      Max Kanat-Alexander
      </a>
    </li>
    <li class="contributor"
      data-contrib-email="math-random-secure@afoolishmanifesto.com"
    >
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" />
      Arthur Axel &quot;fREW&quot; Schmidt
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/FREW" class="author-name">Arthur Axel &quot;fREW&quot; Schmidt</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Math/Random/Secure.pm&#39;" class="">
<option
  selected
  value="FREW/Math-Random-Secure-0.080001"
>0.080001
  (FREW on 2017-03-12)</option>
<option
  
  value="FREW/Math-Random-Secure-0.08"
>0.08
  (FREW on 2016-10-16)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.06"
>0.06
  (MKANAT on 2011-01-25)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.05"
>0.05
  (MKANAT on 2011-01-07)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.04"
>0.04
  (MKANAT on 2011-01-05)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.03"
>0.03
  (MKANAT on 2010-12-30)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.02"
>0.02
  (MKANAT on 2010-12-29)</option>
<option
  
  value="MKANAT/Math-Random-Secure-0.01"
>0.01
  (MKANAT on 2010-12-28)</option>
<optgroup label="BackPAN">'
<option
  
  value="FREW/Math-Random-Secure-0.07"
>0.07
  (FREW on 2016-10-16)</option>
<option
  
  value="FREW/Math-Random-Secure-0.06"
>0.06
  (FREW on 2016-10-16)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Math-Random-Secure">Math-Random-Secure-0.080001</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage two &#10;
          • 18 direct dependents &#10;          • 28 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Math-Random-Secure-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Math-Random-Secure-0.080001">
    <input type="hidden" name="author" value="FREW">
    <input type="hidden" name="distribution" value="Math-Random-Secure">
    <button type="submit" class="favorite highlight"><span>5</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Math::Random::Secure.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>5</span> ++</a>
</div>
   / <span>Math::Random::Secure</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Math::Random::Secure.html#NAME">NAME</a></li>
  <li><a href="./Math::Random::Secure.html#VERSION">VERSION</a></li>
  <li><a href="./Math::Random::Secure.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Math::Random::Secure.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Math::Random::Secure.html#METHODS">METHODS</a>
    <ul>
      <li><a href="./Math::Random::Secure.html#rand">rand</a></li>
      <li><a href="./Math::Random::Secure.html#srand">srand</a></li>
      <li><a href="./Math::Random::Secure.html#irand">irand</a></li>
    </ul>
  </li>
  <li><a href="./Math::Random::Secure.html#IMPLEMENTATION-DETAILS">IMPLEMENTATION DETAILS</a>
    <ul>
      <li><a href="./Math::Random::Secure.html#Making-Math::Random::Secure-Even-More-Secure">Making Math::Random::Secure Even More Secure</a></li>
      <li><a href="./Math::Random::Secure.html#Seed-Exhaustion">Seed Exhaustion</a></li>
    </ul>
  </li>
  <li><a href="./Math::Random::Secure.html#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="./Math::Random::Secure.html#SUPPORT">SUPPORT</a></li>
  <li><a href="./Math::Random::Secure.html#BUGS">BUGS</a></li>
  <li><a href="./Math::Random::Secure.html#AUTHORS">AUTHORS</a></li>
  <li><a href="./Math::Random::Secure.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Math::Random::Secure - Cryptographically-secure, cross-platform replacement for rand()</p>

<h1 id="VERSION">VERSION</h1>

<p>version 0.080001</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> # Replace rand().
 use Math::Random::Secure qw(rand);

 # Get a random number between 0 and 1
 my $float = rand();

 # Get a random integer (faster than int(rand))
 use Math::Random::Secure qw(irand);
 my $int = irand();

 # Random integer between 0 and 9 inclusive.
 $int = irand(10);

 # Random floating-point number greater than or equal to 0.0 and
 # less than 10.0.
 $float = rand(10);</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module is intended to provide a cryptographically-secure replacement for Perl&#39;s built-in <code>rand</code> function. &quot;Crytographically secure&quot;, in this case, means:</p>

<ul>

<li><p>No matter how many numbers you see generated by the random number generator, you cannot guess the future numbers, and you cannot guess the seed.</p>

</li>
<li><p>There are so many possible seeds that it would take decades, centuries, or millenia for an attacker to try them all.</p>

</li>
<li><p>The seed comes from a source that generates relatively strong random data on your platform, so the seed itself will be as random as possible.</p>

<p>See <a href="./Math::Random::Secure.html#IMPLEMENTATION-DETAILS">&quot;IMPLEMENTATION DETAILS&quot;</a> for more information about the underlying systems used to implement all of these guarantees, and some important caveats if you&#39;re going to use this module for some very-high-security purpose.</p>

</li>
</ul>

<h1 id="METHODS">METHODS</h1>

<h2 id="rand">rand</h2>

<p>Should work exactly like Perl&#39;s built-in <code>rand</code>. Will automatically call <code>srand</code> if <code>srand</code> has never been called in this process or thread.</p>

<p>There is one limitation--Math::Random::Secure is backed by a 32-bit random number generator. So if you are on a 64-bit platform and you specify a limit that is greater than 2^32, you are likely to get less-random data.</p>

<h2 id="srand">srand</h2>

<p><b>Note:</b> Under normal circumstances, you should <b>not</b> call this function, as <code>rand</code> and <code>irand</code> will automatically call it for you the first time they are used in a thread or process.</p>

<p>Seeds the random number generator, much like Perl&#39;s built-in <code>srand</code>, except that it uses a much larger and more secure seed. The seed should be passed as a string of bytes, at least 8 bytes in length, and more ideally between 32 and 64 bytes. (See <a href="https://metacpan.org/pod/Math::Random::Secure::RNG#seed">&quot;seed&quot; in Math::Random::Secure::RNG</a> for more info.)</p>

<p>If you do not pass a seed, a seed will be generated automatically using a secure mechanism. See <a href="./Math::Random::Secure.html#IMPLEMENTATION-DETAILS">&quot;IMPLEMENTATION DETAILS&quot;</a> for more information.</p>

<p>This function returns the seed that generated (or the seed that was passed in, if you passed one in).</p>

<h2 id="irand">irand</h2>

<p>Works somewhat like <a href="./Math::Random::Secure.html#rand">&quot;rand&quot;</a>, except that it returns a 32-bit integer between 0 and 2^32. Should be faster than doing <code>int(rand)</code>.</p>

<p>Note that because it returns 32-bit integers, specifying a limit greater than 2^32 will have no effect.</p>

<h1 id="IMPLEMENTATION-DETAILS"><a id="IMPLEMENTATION"></a>IMPLEMENTATION DETAILS</h1>

<p>Currently, Math::Random::Secure is backed by <a href="https://metacpan.org/pod/Math::Random::ISAAC">Math::Random::ISAAC</a>, a cryptographically-strong random number generator with no known serious weaknesses. If there are significant weaknesses found in ISAAC, we will change our backend to a more-secure random number generator. The goal is for Math::Random::Secure to be cryptographically strong, not to represent some specific random number generator.</p>

<p>Math::Random::Secure seeds itself using <a href="https://metacpan.org/pod/Crypt::Random::Source">Crypt::Random::Source</a>. The underlying implementation uses <i>/dev/urandom</i> on Unix-like platforms, and the <code>RtlGenRandom</code> or <code>CryptGenRandom</code> functions on Windows 2000 and above. (There is no support for versions of Windows before Windows 2000.) If any of these seeding sources are not available and you have other <a href="https://metacpan.org/pod/Crypt::Random::Source">Crypt::Random::Source</a> modules installed, Math::Random::Secure will use those other sources to seed itself.</p>

<h2 id="Making-Math::Random::Secure-Even-More-Secure"><a id="Making"></a>Making Math::Random::Secure Even More Secure</h2>

<p>We use <i>/dev/urandom</i> on Unix-like systems, because one of the requirements of duplicating <code>rand</code> is that we never block waiting for seed data, and <i>/dev/random</i> could do that. However, it&#39;s possible that <i>/dev/urandom</i> could run out of &quot;truly random&quot; data and start to use its built-in pseudo-random number generator to generate data. On most systems, this should still provide a very good seed for nearly all uses, but it may not be suitable for very high-security cryptographic circumstances.</p>

<p>For Windows, there are known issues with <code>CryptGenRandom</code> on Windows 2000 and versions of Windows XP before Service Pack 3. However, there is no other built-in method of getting secure random data on Windows, and I suspect that these issues will not be significant for most applications of Math::Random::Secure.</p>

<p>If either of these situations are a problem for your use, you can create your own <a href="https://metacpan.org/pod/Math::Random::Secure::RNG">Math::Random::Secure::RNG</a> object with a different &quot;seeder&quot; argument, and set <code>$Math::Random::Secure::RNG</code> to your own instance of <a href="https://metacpan.org/pod/Math::Random::Secure::RNG">Math::Random::Secure::RNG</a>. The &quot;seeder&quot; is an instance of <a href="https://metacpan.org/pod/Crypt::Random::Source::Base">Crypt::Random::Source::Base</a>, which should allow you to use most random-data sources in existence for your seeder, should you wish.</p>

<h2 id="Seed-Exhaustion"><a id="Seed"></a>Seed Exhaustion</h2>

<p>Perl&#39;s built-in <code>srand</code> reads 32 bits from <i>/dev/urandom</i>. By default, we read 512 bits. This means that we are more likely to exhaust available truly-random data than the built-in <code>srand</code> is, and cause <i>/dev/urandom</i> to fall back on its psuedo-random number generator. Normally this is not a problem, since <a href="./Math::Random::Secure.html#srand">&quot;srand&quot;</a> is only called once per Perl process or thread, but it is something that you should be aware of if you are going to be in a situation where you have many new Perl processes or threads and you have very high security requirements (on the order of generating private SSH or GPG keypairs, SSL private keys, etc.).</p>

<h1 id="SEE-ALSO"><a id="SEE"></a>SEE ALSO</h1>

<dl>

<dt id="http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator"><a id="http"></a><a id="http:-en.wikipedia.org-wiki-Cryptographically_secure_pseudorandom_number_generator"></a><a href="http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator">http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator</a></dt>
<dd>

<p>Describes the requirements and nature of a cryptographically-secure random number generator.</p>

</dd>
<dt id="http://en.wikipedia.org/wiki/CryptGenRandom,"><a id="http1"></a><a id="http:-en.wikipedia.org-wiki-CryptGenRandom"></a><a href="http://en.wikipedia.org/wiki/CryptGenRandom">http://en.wikipedia.org/wiki/CryptGenRandom</a>,</dt>
<dd>

<p>More information about the Windows functions we use to seed ourselves. The article also has some information about the weaknesses in Windows 2000&#39;s <code>CryptGenRandom</code> implementation.</p>

</dd>
<dt id="http://www.computerworld.com/s/article/9048438/Microsoft_confirms_that_XP_contains_random_number_generator_bug"><a id="http2"></a><a id="http:-www.computerworld.com-s-article-9048438-Microsoft_confirms_that_XP_contains_random_number_generator_bug"></a><a href="http://www.computerworld.com/s/article/9048438/Microsoft_confirms_that_XP_contains_random_number_generator_bug">http://www.computerworld.com/s/article/9048438/Microsoft_confirms_that_XP_contains_random_number_generator_bug</a></dt>
<dd>

<p>A news article about the Windows 2000/XP CryptGenRandom weakness, fixed in Vista and XP Service Pack 3.</p>

</dd>
<dt id="http://en.wikipedia.org/wiki/Random_number_generator_attack"><a id="http3"></a><a id="http:-en.wikipedia.org-wiki-Random_number_generator_attack"></a><a href="http://en.wikipedia.org/wiki/Random_number_generator_attack">http://en.wikipedia.org/wiki/Random_number_generator_attack</a></dt>
<dd>

<p>A description of ways to attack a random number generator, which can help in understanding why such a generator needs to be secure.</p>

</dd>
<dt id="Math::Random::Secure::RNG"><a id="Math"></a><a href="https://metacpan.org/pod/Math::Random::Secure::RNG">Math::Random::Secure::RNG</a></dt>
<dd>

<p>The underlying random-number generator and seeding code for Math::Random::Secure.</p>

</dd>
<dt id="Crypt::Source::Random"><a id="Crypt"></a><a href="https://metacpan.org/pod/Crypt::Source::Random">Crypt::Source::Random</a></dt>
<dd>

</dd>
<dt id="Crypt::Random"><a id="Crypt1"></a><a href="./Crypt::Random.html">Crypt::Random</a></dt>
<dd>

</dd>
<dt id="Math::TrulyRandom"><a id="Math1"></a><a href="./Math::TrulyRandom.html">Math::TrulyRandom</a></dt>
<dd>

<p>All of these modules contain generators for &quot;truly random&quot; data, but they don&#39;t contain a simple <code>rand</code> replacement and they can be very slow.</p>

</dd>
</dl>

<h1 id="SUPPORT">SUPPORT</h1>

<p>Right now, the best way to get support for Math::Random::Secure is to email the author using the email address in the <a href="./Math::Random::Secure.html#AUTHORS">&quot;AUTHORS&quot;</a> section below.</p>

<h1 id="BUGS">BUGS</h1>

<p>Math::Random::Secure is relatively new, as of December 2010, but the modules that underlie it are very well-tested and have a long history. However, the author still welcomes all feedback and bug reports, particularly those having to do with the security assurances provided by this module.</p>

<p>You can report a bug by emailing <code>bug-Math-Random-Secure@rt.cpan.org</code> or by using the RT web interface at <a href="https://rt.cpan.org/Ticket/Display.html?Queue=Math-Random-Secure">https://rt.cpan.org/Ticket/Display.html?Queue=Math-Random-Secure</a>. If your bug report is security-sensitive, you may also email it directly to the author using the email address in the <a href="./Math::Random::Secure.html#AUTHORS">&quot;AUTHORS&quot;</a> section below.</p>

<h1 id="AUTHORS">AUTHORS</h1>

<ul>

<li><p>Max Kanat-Alexander &lt;mkanat@cpan.org&gt;</p>

</li>
<li><p>Arthur Axel &quot;fREW&quot; Schmidt &lt;math-random-secure@afoolishmanifesto.com&gt;</p>

</li>
</ul>

<h1 id="COPYRIGHT-AND-LICENSE"><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>This software is Copyright (c) 2010 by BugzillaSource, Inc.</p>

<p>This is free software, licensed under:</p>

<pre><code>  The Artistic License 2.0 (GPL Compatible)</code></pre></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Math::Random::Secure, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Math::Random::Secure</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Math::Random::Secure</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Math::Random::Secure.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
